package com.gm.commonlib.base.baseAdapter;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import java.util.List;
public abstract class CommonAdapter<T> extends BaseAdapter {
    protected LayoutInflater mInflater;
    protected Context mContext;
    protected List<T> mDatas;
    protected final int mItemLayoutId;

    public CommonAdapter(Context context, List<T> mDatas, int itemLayoutId) {
        this.mContext = context;
        this.mInflater = LayoutInflater.from(this.mContext);
        this.mDatas = mDatas;
        this.mItemLayoutId = itemLayoutId;

    }

    public int getCount() {
        return this.mDatas == null ? 0 : this.mDatas.size();
    }

    public T getItem(int position) {
        return this.mDatas.get(position);
    }

    public long getItemId(int position) {
        return (long)position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = this.getViewHolder(position, convertView, parent);
        T item = this.getItem(position);
        viewHolder.setAttached(item);
        this.convert(viewHolder, item);
        return viewHolder.getConvertView();
    }

    public abstract void convert(ViewHolder var1, T var2);

    private ViewHolder getViewHolder(int position, View convertView, ViewGroup parent) {
        return ViewHolder.get(this.mContext, convertView, parent, this.mItemLayoutId, position);
    }


    public void add(T bean) {
        this.mDatas.add(0, bean);
    }

    public void remove(int position) {
        this.mDatas.remove(position);
    }


}

